package com.company;

import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LexicalContextNode;

import java.util.Scanner;

public class Game {
    int count;
    Person p = new Person();
    Monster m = new Monster();
    Scanner input=new Scanner(System.in);

    public void choose() {
        System.out.println("请选择一个人物开始游戏");
        System.out.println("1.小红");
        System.out.println("2.小雅");
        System.out.println("3.小容");
        int character = input.nextInt();
        switch (character) {
            case 1:
                p.name = "小红";
                p.ht = 100;
                p.def = 60;
                p.hp = 200;
                break;
            case 2:
                p.name = "小雅";
                p.ht = 90;
                p.def = 50;
                p.hp = 180;
                break;
            case 3:
                p.name = "小容";
                p.ht = 60;
                p.def = 80;
                p.hp = 260;
                break;
        }
        p.show();
    }

    public void randomMonster() {
        int mon = (int) (Math.random() * 3 + 1);
        switch (mon) {
            case 1:
                m.name = "厄喙兽";
                m.ht = 20;
                m.def = 60;
                m.hp = 100;
                break;
            case 2:
                m.name = "苍狼";
                m.ht = 70;
                m.def = 50;
                m.hp = 120;
                break;
            case 3:
                m.name = "鹿妖";
                m.ht = 30;
                m.def = 80;
                m.hp = 160;
                break;
        }
        m.show();
    }

        public void start(){
            choose();
            System.out.println("开始游戏啦！（y：开始，n:再等等）");
            String yn = input.next();
            if (yn.equals("y")) {
                while (2 == 2) {
                    randomMonster();
                    int deHp = p.hurt(m.def);
                    if (deHp < 0) {
                        deHp = 0;
                        count++;
                    }
                    m.hp -= deHp;

                    System.out.println("你对" + m.name + "造成了" + deHp + "点伤害");

                    if (m.hp <= 0) {
                        count++;
                        break;
                    } else {
                        m.show();

                        int dH = m.hurt(p.def);
                        if (dH < 0) {
                            dH = 0;
                        }
                        p.hp -= dH;
                        System.out.println(m.name + "对你造成了" + dH + "点伤害");
                        p.show();
                        if (p.hp < 0) {
                            count++;
                            System.out.println("很不幸，你被怪物击败了！");
                            break;
                        }
                    }
                    if (p.hp > m.hp) {
                        count++;
                        System.out.println("你击败了" + m.name + ",是否继续游戏？（y：继续，n:结束）");
                        String y = input.next();
                        if (y.equals("n")) {
                            p.show();
                            System.out.println("你一共击败了" + count + "个怪物");
                            break;
                        }
                    }
                }
            } else {
                System.out.println("你一共击败了" + count + "个怪物");
            }
        }
    }

